package com.xr.web.controller.miniprogram;

import com.xr.common.annotation.Log;
import com.xr.common.core.controller.BaseController;
import com.xr.common.core.domain.AjaxResult;
import com.xr.common.core.page.TableDataInfo;
import com.xr.common.enums.BusinessType;
import com.xr.miniprogram.domain.MiniProgramSwiper;
import com.xr.miniprogram.service.IMiniProgramSwiperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:首页轮播图模块接口
 *
 * @author: wls
 * @date: 2023/11/9 11:24
 * @version:1.0
 */
@Api("首页轮播图模块接口")
@RestController
@RequestMapping("/mini/swiper")
public class MpSwiperController extends BaseController {
    @Resource
    private IMiniProgramSwiperService swiperService;

    @ApiOperation("分页获取首页轮播图列表")
    @PreAuthorize("@ss.hasPermi('mini:swiper:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniProgramSwiper miniProgramSwiper){
        startPage();
        List<MiniProgramSwiper> list =swiperService.selectSwiperList(miniProgramSwiper);
        return getDataTable(list);
    }

    /**
     * 添加Swiper
     * @param miniProgramSwiper
     * @return
     */
    @ApiOperation("添加轮播图")
    @PreAuthorize("@ss.hasPermi('mini:swiper:add')")
    @Log(title = "首页轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@ApiParam(value = "轮播图对象", required = true) @RequestBody MiniProgramSwiper miniProgramSwiper){
        return toAjax(swiperService.insertSwiper(miniProgramSwiper));
    }

    /**
     * 修改Swiper
     * @param miniProgramSwiper
     * @return
     */
    @ApiOperation("修改轮播图")
    @PreAuthorize("@ss.hasPermi('mini:swiper:edit')")
    @Log(title = "首页轮播图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@ApiParam(value = "轮播图对象", required = true) @RequestBody MiniProgramSwiper miniProgramSwiper){
        return toAjax(swiperService.updateSwiper(miniProgramSwiper));
    }

    @ApiOperation("根据id获取轮播图")
    @PreAuthorize("@ss.hasPermi('mini:swiper:query')")
    @GetMapping("/get")
    public AjaxResult getById(@ApiParam(value = "轮播图id", required = true) @RequestParam("id") Long id){
        return success(swiperService.selectSwiperById(id));
    }

    @ApiOperation("根据id删除轮播图")
    @PreAuthorize("@ss.hasPermi('mini:swiper:remove')")
    @Log(title = "首页轮播图", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(swiperService.deleteSwiperByIds(ids));
    }
}
